<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html>
<jsp:include page="/cnbdw/commons/item_state.jsp"/>
<input type="hidden" name="id" id="id" value="${id}">
<input type="hidden" name="createTime" value="${createTime}">
<input type="hidden" name="createUser" value="${createUser}">
<input type="hidden" name="bedNo" value="${bedNo}"/>
<input type="hidden" name="itemInfo" value="${itemInfo}"/>
<input type="hidden" name="employeeNum" value="${employeeNum}">
<input type="hidden" name="locked" value="${locked}">
<input type="hidden" name="badisempty" value="0">
<table style="width: 100%;" class="listtable">
        <tr class="row-even">
            <td class="tr_left" style="width: 15%;"><span class="required">*</span>舱室编号:&nbsp;</td>
            <td class="tr_right" style="width: 35%;">
                <input type="text" name="roomNo" value="${roomNo}"   class="easyui-validatebox" data-options="required:true,missingMessage:'请输入舱室编号'"/>
            </td>
            <td class="tr_left" style="width: 15%;"><span class="required">*</span>舱室种类:&nbsp;</td>
            <td class="tr_right" style="width: 35%;">
            	<input type="text" id="select_type" name="type" value="${type}"
                   class="easyui-combobox" data-options="required:true,missingMessage:'请选择舱室种类'"/>
            </td>
        </tr>
        <tr>
            <td class="tr_left" style="width: 15%;"><span class="required">*</span>甲&nbsp;&nbsp;板:&nbsp;</td>
            <td class="tr_right" style="width: 35%;">
            	<input type="text" id="select_deckinfo" name="deck" value="${deck}"
                   class="easyui-combobox" data-options="required:true,missingMessage:'请选择甲板'"/>
            </td>
            <td class="tr_left" style="width: 15%;"><span class="required">*</span>报警级别:&nbsp;</td>
            <td class="tr_right" style="width: 35%;">
            	<input type="text" id="select_reqioninfo" name="area" value="${area}"
                   class="easyui-combobox" data-options="required:true,missingMessage:'请选择舱室报警级别'"/>
            </td>
        </tr>
        <tr class="row-even">
            <td class="tr_left" style="width: 15%;"><span class="required">*</span>锁&nbsp;&nbsp;号:&nbsp;</td>
            <td class="tr_right" style="width: 35%;">
                <input type="text" name="doorNo" value="${doorNo}"   class="easyui-validatebox" data-options="required:true,missingMessage:'请输入锁号'"/>
            </td>
            <td class="tr_left">&nbsp;&nbsp;&nbsp;</td>
            <td class="tr_right">&nbsp;&nbsp;&nbsp;</td>
        </tr>
        <tr class="row-even" id="addbed"<s:if test="props!=1"> style="display: none;"</s:if>>
            <td class="tr_left" id="ab" style="width: 15%;"><span class="required">*</span>床&nbsp;&nbsp;位:&nbsp;</td>
            <td class="tr_right" style="width:35%;">&nbsp;&nbsp;&nbsp;</td>
              <td class="tr_left" id="ai" style="width: 15%;"><span class="required">*</span>物&nbsp;&nbsp;品:&nbsp;</td>
              <td class="tr_right" style="width:35%;">&nbsp;&nbsp;&nbsp;</td>
        </tr>
        <tr id="addbed2"<s:if test="props!=1"> style="display: none;"</s:if>>
          <td class="tr_right" style="width:15%;">&nbsp;&nbsp;&nbsp;</td>
            <td class="tr_right"  id="ab1" style="width: 35%;">
            	<table   id="mytable" ></table>
            	<div id="mytable_toobar" class="etl_panel_title">
                     <a href="javascript:void(0);" onclick="addLine()" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" style="float:left;">新增</a>
                </div>
		    </td>
			 <td class="tr_right" style="width:15%;">&nbsp;&nbsp;&nbsp;</td>
            <td class="tr_right"  id="ai1" style="width: 35%;">
            	<table id="mytable1" ></table>
            	<div id="mytable_toobar1" class="etl_panel_title">
                  <a href="javascript:void(0);" onclick="addLine1()" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" style="float:left;">新增</a>         
                </div>
			</td>
			
        </tr>
        
       
         <tr class="row-even">
            <td class="tr_left"><span class="required">*</span>备&nbsp;&nbsp;注:&nbsp;</td>
            <td class="tr_right">
                <input type="text" name="remark" value="${remark}" style="width:300px;" maxlength="200"  class="easyui-validatebox" />
            </td>
            <td class="tr_left">&nbsp;&nbsp;&nbsp;</td>
            <td class="tr_right">&nbsp;&nbsp;&nbsp;</td>
            
        </tr>
    </table>
<script type="text/javascript"> 
	
	
	
	$(function(){ 
	    $('#select_type').combobox({
	        url:'${pageContext.request.contextPath}/roomTypeAction!getTypeSelectData.action',
	        valueField:'id',
	        textField:'name',
	        editable:false,
	        onChange:function(newValue,oldValue){
	        	$.ajax({
	                url: '${pageContext.request.contextPath}/roomTypeAction!getTypeValue.action',
	                dataType: 'json',
	                data: {id: newValue},
	                success: function (data){
	                	if(data.type==1){
	                	   // alert(data.type);
	                		$("#addbed").show();
	                		$("#addbed2").show();
	                		$("#ab").show();
	                		$("#ab1").show();
	                		
	                	}else{
	                	 	
	                		$("#ab").hide();
	                		$("#ab1").hide();
	                		
	                	}
	                }
	            });
	        }
	    });
	});
	$(function(){ 
	    $('#select_reqioninfo').combobox({
	        url:'${pageContext.request.contextPath}/regionInfoAction!getRegionInfoSelectData.action',
	        valueField:'id',
	        textField:'name',
	        editable:false
	    });
	});
	$(function(){ 
	    $('#select_deckinfo').combobox({
	        url:'${pageContext.request.contextPath}/deckInfoAction!getDeckInfoSelectData.action',
	        valueField:'id',
	        textField:'name',
	        editable:false
	    });

	});
	
	
	$(document).ready(function(){
		fLoadTable();
		fLoadTable1();
		fLoadData();
		fLoadData1();
	})	
	function fLoadData(){
		
	var myid = $("#id").val();
	//alert(myid+"2")
		if(myid==0||myid=='')return;
		$.ajax({
			 url: '${pageContext.request.contextPath}/roomAction!getBedInfoList.action',
			 dataType: 'json',
			 data: {id: myid},
			 success: function (data) {
			 
			
					$('#mytable').datagrid('loadData', data);
			 	
			 }
			});
	};
	function fLoadTable(){
		$('#mytable').datagrid({
               resizable:true,
               rownumbers:true,
				width: 300,
				height: 200,
				//fitColumns: false,
				columns:[[
				  {field:'id',checkbox: true},
					{field:'bedNo',title:'床号',editor:'text' ,formatter: function (value, rowData, rowIndex) {
						//alert(value.bedNo);
						if (value == '') {return '--'} return value;}
							},
					{field: 'action', title: '操作', align: 'right',
                        formatter: function (value, row, index) {
                    	  if (row.editing){
                              var s = '<a href="#" onclick="saverow('+index+')">保存</a> ';
                              var c = '<a href="#" onclick="cancelrow('+index+')">取消</a>';
                                  return s+c;
                            }else {
                              var e = '<a href="#" onclick="editrow('+index+')">编辑</a> ';
                              var d = '<a href="#" onclick="delLine(this,\'' + row.id + '\')">删除</a>';
                              return e+d;
                            }
                        }
                    }
				 ]],
        onBeforeEdit:function(index,row){
           row.editing = true;
           $('#mytable').datagrid('refreshRow', index);
        },
    onAfterEdit:function(index,row){
    	//var roomId = $("#id").val();
    	//var bedNo=row.bedNo;
      //var bedId=row.id;
		//if(roomId==0||roomId=='')return;
		//$.ajax({
		//	 url: '${pageContext.request.contextPath}/roomAction!insertBedData.action',
		//	 dataType: 'json',
		//	 data: {roomId: roomId,bedNo:bedNo,bedId:bedId},
		//	 success: function (data) {
			 
			
		//			alert(success);
			 	
		//	 }
		//	});
        row.editing = false;
        
        $('#mytable').datagrid('refreshRow', index);
        
       
       // document.getElementById("ids").value=ids;
       // document.getElementById("idNos").value=idNos;
    },
    onCancelEdit:function(index,row){
        row.editing = false;
        $('#mytable').datagrid('refreshRow', index);
    },
        toolbar: '#mytable_toobar'
    });
		
		};
		
		
		
		
		function fLoadTable1(){
		
		  $('#mytable1').datagrid({
      
                rownumbers:true,
				width: 300,
				height: 200,
				// resizable:false,
				//fitColumns: false,
				//autoSizeColumn:true,
				columns:[[
				  {field:'id',checkbox: true},
					{field:'itemNo',title:'物品名',editor:'text' ,formatter: function (value, rowData, rowIndex) {if (value == '') {return '--'} return value;}},
					{field:'state',title:'状态',editor:'text' ,formatter: function (value, rowData, rowIndex) {if (value == '') {return '--'} return value;}},
					
					{field: 'action', title: '操作', align: 'right',
                    formatter: function (value, row, index) {
                    	  if (row.editing){
                    var s = '<a href="#" onclick="saverow1('+index+')">保存</a> ';
                    var c = '<a href="#" onclick="cancelrow1('+index+')">取消</a>';
                    return s+c;
                       } else {
                    var e = '<a href="#" onclick="editrow1('+index+')">编辑</a> ';
                    var d = '<a href="#" onclick="delLine1(this,\'' + row.id + '\')">删除</a>';
                    return e+d;
                }
                }
              }
				]],
    onBeforeEdit:function(index,row){
        row.editing = true;
        $('#mytable1').datagrid('refreshRow', index);
    },
    onAfterEdit:function(index,row){
    	
        row.editing = false;
        $('#mytable1').datagrid('refreshRow', index);
        
      
    },
    onCancelEdit:function(index,row){
        row.editing = false;
        $('#mytable1').datagrid('refreshRow', index);
    },
        toolbar: '#mytable_toobar1'
    });
		
		};
		
		
		
		
		
		
		function editrow(index){

          $('#mytable').datagrid('beginEdit', index);

            }



        function saverow(index){

          $('#mytable').datagrid('acceptChanges');

            }

        function cancelrow(index){

          $('#mytable').datagrid('cancelEdit', index);

            }
		
		
		function editrow1(index){

          $('#mytable1').datagrid('beginEdit', index);

            }



        function saverow1(index){

          $('#mytable1').datagrid('acceptChanges');

            }

        function cancelrow1(index){

          $('#mytable1').datagrid('cancelEdit', index);

            }
		
		
		
		
	
	//==
	function fLoadData1(){ 
		var myid = $("#id").val();
		
		if(myid==0||myid=='')return;
		$.ajax({
			 url: '${pageContext.request.contextPath}/roomAction!getItemInfoList.action',
			 dataType: 'json',
			 data: {id: myid},
			 success: function (data) {
			
			$('#mytable1').datagrid('loadData', data);
			 
			 	
			 }
		});
	};
	function addLine(){
		//alert("lll1111232");
		
	  $('#mytable').datagrid('insertRow',{
	   //fitColumns: false,
	  //  resizable:true,
	    row: {
		      bedNo: '',
	         }
       });
    };

      function addLine1(){
		//  alert("111");
		   $('#mytable1').datagrid('insertRow',{
		//fitColumns: true,
		// resizable:true,
	     row: {
		   itemNo: '',
		   state:''	
	     }
          });
      };

	
	
	$(function(){ 
    $('#search_select_state').combobox({
        url:'${pageContext.request.contextPath}/roomAction!getStateSelectData.action',
        valueField:'id',
        textField:'name',
        editable:false
    });
    })
	function delLine(obj,did){
	
		if(did=="undefined"){
			$(obj).parent().remove();
				reflash();
			$.messager.show({
                title: '提示',
                msg: '删除成功'
            });
		}else{
			$.ajax({
	            url: '${pageContext.request.contextPath}/roomAction!deleteBed.action',
	            dataType: 'json',
	            data: {id: did},
	            success: function (data) {
	            	if(data.returnFlag){
						$(obj).parent().remove();
						
	            	}
	            	reflash();
	           		$.messager.show({
	                    title: '提示',
	                    msg: data.returnMsg
	                });
	            }
	        });
		}
	} 
	function reflash(){
	fLoadTable();
		fLoadData();
		fLoadTable1();
		fLoadData1();
	}
	//==
	function delLine1(obj,did){
	//alert(did);
		if(did=="undefined"){
		//alert("222");
			$(obj).parent().remove();
				reflash();
			$.messager.show({
                title: '提示',
                msg: '删除成功'
            });
		 }else{
			$.ajax({
	            url: '${pageContext.request.contextPath}/roomAction!deleteItem.action',
	            dataType: 'json',
	            data: {id: did},
	            success: function (data) {
	            	if(data.returnFlag){
						$(obj).parent().remove();
						
	            	}
	            	reflash();
	           		$.messager.show({
	                    title: '提示',
	                    msg: data.returnMsg
	                });
	            }
	        });
		 }
	} 
	
	
	
</script>